package com.tianzhu.config;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.web.filter.GenericFilterBean;

import com.tianzhu.util.ApplicationUtils;

@Slf4j
public class MDCUsernameInsertingFilter extends GenericFilterBean implements InitializingBean {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        //MDC.putUsername(ApplicationUtils.getUsername());
    	org.slf4j.MDC.put("username", ApplicationUtils.getUsername());
        chain.doFilter(request, response);
    }

}
